<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Validator;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        //手机验证
        Validator::extend('phone', function($attribute, $value, $parameters, $validator) {
            return preg_match('/^1[3|4|5|7|8]{1}\d{9}/i', $value) && strlen($value) == 11;
        });        

        Validator::replacer('phone', function($message, $attribute, $rule, $parameters) {
            return str_replace('attribute', $attribute, 'attribute is invalid phone number');
        });          
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}
